package conson.tech.manage.common.util;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * ClassName: DateUtil
 * Description: 时间工具
 * Author: HXL
 * Date: 2020/4/30 10:48 上午
 * Version: 1.0
 */
public class DateUtil {

    private static String pattern = "yyyy-MM-dd HH:mm:ss";

    public static LocalDateTime getLocalDateTime(String dateStr){
        if (dateStr.indexOf(":") == -1 && dateStr.indexOf(" ") == -1){
            dateStr += " 00:00:00";
        }else if (dateStr.indexOf(":") == -1 && dateStr.indexOf(" ") != -1){
            dateStr += ":00:00";
        }else{
            String[] split = dateStr.split(":");
            if (split.length == 2){
                dateStr += ":00";
            }
        }
        return LocalDateTime.parse(dateStr, DateTimeFormatter.ofPattern(pattern));
    }
    public static String getLocalDateTimeStr(LocalDateTime localDateTime){
        DateTimeFormatter formatter=DateTimeFormatter.ofPattern(pattern);
        return formatter.format(localDateTime);
    }

    public static void main(String[] args) {
        String string = "2020-05-28 12:12";
        LocalDateTime localDateTime = DateUtil.getLocalDateTime(string);
        System.out.println(localDateTime);
    }
}
